<template>
	<view class="page_view">
		<view class="title">
			选择平台商户
		</view>
		<view class="seach-view" @tap="go_choose_pingtai"> 
			{{picker_val.shopname?picker_val.shopname:'选择平台'}}
		</view>
		<view class="title">
			上传发票
		</view>
		<view class="choose_img" @tap="choose_img" v-if="!fp_img">
			<image src="/static/images/user/Group13461@2x.png"  class="choose_img_icon" mode=""></image>
		</view>
		<view class="choose_img" @tap="choose_img" v-else="fp_img">
			<image :src="fp_img"  class="choose_imafe" mode=""></image>
		</view>
		<view class="title">
			输入发票金额
		</view>
		<view class="jine">
			<input type="number" class="jine_input" placeholder="输入" v-model="money">
			<view style="color: #DFDFDF;">|</view>
			<view class="jine_right">
				元
			</view>
		</view>
		<view class="btn" @tap="submit">
			提交审核
		</view>
		
	</view>
</template>

<script> 
	export default {
		data() {
			return {
				platform:'',
				fp_img:'',
				money:'',
				show:false,
				picker_index:0,
				picker_list:[],
				picker_val:{
					shopname:''
				},
				pingtai_list:[],
				pingtai_id:'',
				img_url:'',
				
			}
		},
		onNavigationBarButtonTap() {
			uni.navigateTo({
				url:'/pages/UserCenter/InvoiceList/InvoiceList'
			})
		},
		onLoad() {
			this.get_pingtai()
		},
		onShow() {
			console.log(this.picker_val)
		},
		methods: {
			go_choose_pingtai(){
				uni.navigateTo({
					url:'/pages/UserCenter/UploadInvoice/seach_pingtai/seach_pingtai'
				})
			},
			PickerChange(e){
				this.picker_index = e.detail.value
				this.picker_val = this.picker_list[this.picker_index]
				this.pingtai_id = this.pingtai_list[this.picker_index].id
			},
			get_pingtai(){
				let t = this
				t.$post({
					url:'/wanlshop/tickets/get_shop_list'
				}).then(res=>{
					console.log(res)
					if(res.code == 1){
						t.pingtai_list = res.data
						for(let item of t.pingtai_list){
							t.picker_list.push(item.shopname)
						}
					}
				})
			},
			async choose_img(){
		
				//#ifdef APP-PLUS
				let result = await this.$store.dispatch("quanxian/requestPermissions",'WRITE_EXTERNAL_STORAGE')
					console.log(result)
				if (result !== 1) return
				this.$store.state.isCAMERA = true
				// #endif
				
				let that = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album','camera'], //从相册选择
					success: function (res) {
						console.log(res.tempFilePaths);
						let fp_img = res.tempFilePaths[0]
						that.$api.get({
							url: '/wanlshop/common/uploadData',
							success: updata => {
								console.log(updata)
								that.$api.upload({
									url: updata.data.uploadurl,
									filePath:fp_img,
									name: 'file',
									formData: updata.data.storage == 'local' ? null : updata.data.multipart,
									success: res => {
										let resinfo = JSON.parse(res)
										that.fp_img = resinfo.data.fullurl
										that.img_url = resinfo.data.url
									}
								});
							}
						});
					}
				});
			},
			submit(){
				let t = this
				if(!t.picker_val.shopname){
					uni.showToast({
						title:'请选择发票平台',
						icon:'none'
					})
					return
				}
				
				if(!t.fp_img){
					uni.showToast({
						title:'请上传发票图片',
						icon:'none'
					})
					return
				}
				
				if(!t.money){
					uni.showToast({
						title:'请输入发票金额',
						icon:'none'
					})
					return
				}
				this.$post({
					url:'/wanlshop/tickets/save_invoice',
					data:{
						shopid:t.picker_val.id,
						img:t.img_url,
						price:t.money
					}
				}).then(res=>{
					console.log(res)
					if(res.code == 1){
						uni.showToast({
							title:'上传成功',
							icon:'none'
						})
						setTimeout(()=>{
							uni.redirectTo({
								url:'/pages/UserCenter/InvoiceList/InvoiceList'
							})
						},1500)
						
					}else{
						uni.showToast({
							title:res.msg,
							icon:'none'
						})
					}
				})
			}
		}
	}
</script>

<style scoped>
	.page_view{
		padding: 0 32rpx;
	}
.title{
	font-size: 28rpx;
	font-family: Alibaba PuHuiTi 2.0-65 Medium, Alibaba PuHuiTi 20;
	font-weight: normal;
	color: #000000;
	padding-top: 40rpx;
}

.seach-view{
	width: 690rpx;
	height: 82rpx;
	background: #F4F4F4;
	border-radius: 12rpx;
	padding-left: 12rpx;
	font-size: 28rpx;
	font-family: Alibaba PuHuiTi 2.0-55 Regular, Alibaba PuHuiTi 20;
	font-weight: normal;
	color: #333333;
	margin-top: 20rpx;
	line-height: 82rpx;
	padding-left: 20rpx;
}
.choose_img{
	width: 260rpx;
	height: 260rpx;
	background: #F4F4F4;
	border-radius: 16rpx;
	margin-top: 20rpx;
	display: flex;
	align-items: center;
}
.choose_imafe{
	width: 260rpx;
	height: 260rpx;
	background: #F4F4F4;
	border-radius: 16rpx;
}
.choose_img_icon{
	width: 72rpx;
	height: 72rpx;
	margin: 0 auto;
}
.jine{
	width: 690rpx;
	height: 82rpx;
	background: #F4F4F4;
	border-radius: 12rpx 12rpx 12rpx 12rpx;
	margin-top: 20rpx;
	display: flex;
	align-items: center;
	padding: 0 20rpx;
	
}
.jine_input{
	width: 85%;
	height: 82rpx;
	padding-left: 12rpx;
}
.jine_right{
	width: 14%;
	font-size: 28rpx;
	font-family: Alibaba PuHuiTi 2.0-55 Regular, Alibaba PuHuiTi 20;
	font-weight: normal;
	color: #333333;
	text-align: center;
}
.btn{
	width: 700rpx;
	height: 96rpx;
	background: linear-gradient(180deg, #E46C30 0%, #E32C1C 100%);
	border-radius: 48rpx;
	position: fixed;
	bottom: 100rpx;
	left: 25rpx;
	text-align: center;
	line-height: 96rpx;
	font-size: 30rpx;
	font-family: Alibaba PuHuiTi 2.0-65 Medium, Alibaba PuHuiTi 20;
	font-weight: normal;
	color: #FFFFFF;
}
</style>
